package com.zf.spring.microservice.zuul.common.filters;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.springframework.cloud.netflix.zuul.filters.SimpleRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;

public class CustomRouteLocator extends SimpleRouteLocator {
	private final Map<String, ZuulRoute> routes = new HashMap<>();

	public CustomRouteLocator(Collection<ZuulRoute> routes, String servletPath,
			ZuulProperties properties) {
		super(servletPath, properties);
		for (ZuulRoute route : routes) {
			this.routes.put(route.getPath(), route);
		}
	}

	@Override
	protected Map<String, ZuulRoute> locateRoutes() {
		return Collections.unmodifiableMap(this.routes);
	}
}
